// pages/my_account_assoplat_info/assoplat_info_index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isBinding: false,
    username: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.info("options=%o", options)
    //这里有一个比较坑的地方，URL传参数，过来类型默认是字符串类型
    let isBinding = options.isBinding == 'true'
    if(isBinding){
      this.setData({
        isBinding: isBinding,
        username: 'qiyang'
      })
    }
    console.info(this.data.isBinding)
  }, removeBinding: function(){
    //关联关联
    wx.showModal({
      title: '是否取消关联',
      content: '您将取消' + this.data.username + '该账号与当前投优选账号的关联关系',
      confirmText: "确认",
      cancelText: "取消",
      success: function (res) {
        console.log(res);
        if (res.confirm) {

          wx.showModal({
            content: '操作成功',
            showCancel: false,
            success: function (res) {
              if (res.confirm) {
                wx.navigateBack({
                  delta: 1
                })
              }
            }
          });

        } else {
          console.log('不取消关联了')
        }
      }
    });
  }, submitLoginInfo: function (e){
    console.info("提交用户登录信息进行关联")
    var formInfo = e.detail.value;
    if(!formInfo.username){
      wx.showToast({
        title: '请输入登录的用户名',
        icon: 'none'
      })
      return;
    }

    //验证用户名密码及验证码 省略


    //确认关联
    wx.showModal({
      title: '是否确认关联',
      content: '您将关联' + formInfo.username + '该账号到当前投优选账号？',
      confirmText: "确认关联",
      cancelText: "取消",
      success: function (res) {
        console.log(res);
        if (res.confirm) {

          wx.showModal({
            content: '关联成功',
            showCancel: false,
            success: function (res) {
              if (res.confirm) {
                wx.navigateBack({
                  delta: 1
                })
              }
            }
          });

        } else {
          console.log('不解关联了')
        }
      }
    });

  }
})